# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2023年03月21日
"""
import openpyxl

myBook=openpyxl.load_workbook('股价表.xlsx',data_only=True)
mySheet=myBook.active
myNewBook=openpyxl.Workbook()
myNewSheet=myNewBook.active
myNewSheet.title='股价表'
myNewSheet.append(['股票名称','成交均价'])
myRows=list(mySheet.values)[1:]
myDict={}
for myRow in myRows:
	if myRow[1] in myDict.keys():
		myDict[myRow[1]]+=[myRow]
	else:
		myDict[myRow[1]]=[myRow]

for myStock in myDict.keys():
	myPrice=sum([myRow[2] for myRow in myDict[myStock]])/len(myDict[myStock])
	myNewSheet.append([myStock,myPrice])

myNewBook.save('结果表-股价表.xlsx')

